<template>
	<div class="" style="width: 100%;">
		<head-top></head-top>

		<div class="table_container" :style="'width: 90%;  overflow: hidden;  '">
			<div style="margin: 5px; display: flex;">
				<div>
					<span style="font-size: xx-large; padding: 10px;">修改margin:</span>
				</div>

				<span style="font-size: medium; padding: 10px;">账户列表:</span>
				<el-select v-model="account_choice" size="small" clearable filterable placeholder="请选择"
					@change="changedate_choice()">
					<el-option v-for="item in account_options" :key="item.label" :label="item.label"
						:value="item.value">
					</el-option>
				</el-select>
				<el-button style="margin-left: 20px;" size="mini" type="success" @click="refleash()">刷新</el-button>
			</div>
			<!-- <div style="margin: 5px; display: flex; height: 400px;">
				<el-table ref="singleTable" :data="arrange_data" height="100%" border size='small' :fit='true'
					:style="'width:'+(screenWidth*1.0)+'px;'">
					<el-table-column prop="program_code" label="program_code" align></el-table-column>
					<el-table-column prop="do_datetime" label="datetime" sortable align></el-table-column>
					<el-table-column prop="margin_change" label="margin_change" sortable align></el-table-column>
					<el-table-column prop="margin_set" label="margin_set" align></el-table-column>
					<el-table-column prop="ip" label="ip" sortable align></el-table-column>
					<el-table-column prop="user" label="user" sortable align></el-table-column>
					<el-table-column prop="product_properties" label="产品属性" sortable align></el-table-column>
					<el-table-column prop="old_margin" label="old_margin" sortable align></el-table-column>
					<el-table-column prop="after_margin" label="after_margin" sortable align></el-table-column>
					<el-table-column prop="status" label="status" sortable align></el-table-column>
				</el-table>


			</div> -->
			<div style="margin: 5px; display: flex; width: 100%;">


				<span style="font-size: medium; padding: 10px;"> {{program_code_choice}} -修改margin: </span>

				<span style="font-size: medium; padding: 10px;">margin_change:</span>
				<el-input v-model="margin_change" size="small" style="width: 20%;" placeholder="0是不变"></el-input>
				<span style="font-size: medium; padding: 10px;">margin_set:</span>
				<el-input v-model="margin_set" size="small" style="width: 20%;" placeholder="0是不变"></el-input>
				<el-button style="margin-left: 20px;" size="mini" type="success"  @click="change_margin()">执行</el-button>

			</div>
			<div style="margin: 5px; display: flex; align-items: center;">
				<span class="result-label">结果:</span>
				<pre class="result-pre">
					<span v-html="result"></span>
				</pre>
				<!-- <span style="font-size: medium; padding: 10px;">结果:</span>
				<pre style="font-size: medium;
		        padding: 10px;   border: 1px solid #ccc;
		        min-width: 30%;flex: 1;
		        min-height: 60px;
		      " v-html="result"></pr -->
			</div>
		</div>
		<div class="table_container" :style="'width: 90%;  overflow: hidden;  '">
			<div style="margin: 5px; display: flex;">
				<div>
					<span style="font-size: xx-large; padding: 10px;">查询出金额度:</span>
				</div>
		
				<span style="font-size: medium; padding: 10px;">账户列表:</span>
				<el-select v-model="account_choice" size="small" clearable filterable placeholder="请选择"
					@change="changedate_choice()">
					<el-option v-for="item in account_options" :key="item.label" :label="item.label"
						:value="item.value">
					</el-option>
				</el-select>
				
				
				<el-button style="margin-left: 20px;" size="mini" type="success" @click="get_money_list()">执行</el-button>
			</div>
		
			<div style="margin: 5px; display: flex; align-items: center; flex: 1; min-height: 0;">
			   <div class="result-container">
					<span class="result-label">结果:</span>
					<pre class="result-pre">
						<span v-html="moneyresult"></span>
					</pre>
				</div>
			</div>
		
		</div>
		<div class="table_container" :style="'width: 90%;  overflow: hidden;  '">
			<div style="margin: 5px; display: flex;">


				<div>
					<span style="font-size: xx-large; padding: 10px;">卖出symbol:</span>
				</div>

				<span style="font-size: medium; padding: 10px;">账户列表:</span>
				<el-select v-model="program_code_choice" size="small" clearable filterable placeholder="请选择"
					@change="changedate_choice()">
					<el-option v-for="item in program_code_options" :key="item.label" :label="item.label"
						:value="item.value">
					</el-option>
				</el-select>
				<span style="font-size: small; padding: 10px;">symbol:</span>
				<el-input v-model="symbol" size="small" style="width: 20%;" placeholder="卖出合约比如600000"></el-input>
				<span style="font-size: small; padding: 10px;">price:</span>
				<el-input v-model="price" size="small" style="width: 20%;" placeholder="卖出价格比如6.38"></el-input>
				
				
				<el-button style="margin-left: 20px;" size="mini" type="success" @click="get_sell_list()">执行</el-button>
			</div>

			<div style="margin: 5px; display: flex; align-items: center; flex: 1; min-height: 0;">
			   <div class="result-container">
					<span class="result-label">结果:</span>
					<pre class="result-pre">
						<span v-html="sellresult"></span>
					</pre>
				</div>
			</div>

		</div>
		
	</div>
</template>

<script>
	import headTop from '@/components/headTop'
	export default {
		data() {
			return {
				checkflag: false,
				program_code_choice: "",
				program_code_options: [],
				account_choice: "",
				account_options: [],
				margin_change: 0,
				margin_set: 0,
				symbol:'600000',
				price:'0.0',
				count: 0,
				LP_account_list: [],
				result: "",
				sellresult:'',
				moneyresult:'',
				screenWidth: document.body.clientWidth, // 屏幕尺寸
				screenHeight: document.body.clientHeight, // 屏幕尺寸
				opid: "0",
				arrange_data: [],
				allow_readpw: 'no',





			}
		},
		components: {
			headTop,
		},



		activated() {

			// console.log("当前登入用户", this.$store.state.adminInfo.name);
			//    if (this.tradesysPermission_list.indexOf (this.$store.state.adminInfo.permission) ==-1) {
			// 	console.log(this.$store.state.adminInfo.name,"未登入")
			// 	this.$message({type: 'error',	message: '没有权限',});
			// 	this.$router.push({
			// 		path: `/manage`
			// 	})
			// }
		},
		created() {
			this.get_exchange_arrange()
			this.get_tradesys_account()
		},
		computed: {

		},

		methods: {
			changedate_choice() {

				this.get_exchange_arrange()
			},

			changeprogram_code_choice() {
				this.get_exchange_arrange()
			},



			refleash() {
				this.get_exchange_arrange()
			},
			get_sell_list() {
				var that = this
				const data = {
					module_name: "yxk_tool.check_server",
					function_name: "get_sell_list",
					args: [this.symbol,this.price],
					kwargs: {
						program_code:this.program_code_choice
					}
				};



				that.$axios.post(that.lpcallfunction, data).then(response => {
					console.log(response.data[0], 'get_sell_list');
					if (response.status = 200) {
						if (response.data[0].code == 'error') {
							this.$message({
								message: response.data[0].message,
								type: 'error'
							});

						} else {
							this.$message({
								message: '完成',
								type: 'success'
							});
							that.sellresult = response.data[0].message.trim()
						}
					} else {
						console.log(response.data[0].statusCode);
					}

				})
			},
			get_money_list() {
				if (this.account_choice==''){
					
					this.$message({
						type: 'info',
						message: '请选择账号',
				
					});
					that.moneyresult =''
					return
				}
				var that = this
				const data = {
					module_name: "yxk_tool.check_server",
					function_name: "get_moneyout_last",
					args: [this.account_choice],
					kwargs: {}
					
				};
				that.$axios.post(that.lpcallfunction, data).then(response => {
					console.log(response.data[0], 'get_moneyout_last');
					if (response.status = 200) {
						if (response.data[0].code == 'error') {
							this.$message({
								message: response.data[0].message,
								type: 'error'
							});
			
						} else {
							this.$message({
								message: '完成',
								type: 'success'
							});
							that.moneyresult = response.data[0].message.trim()
						}
					} else {
						console.log(response.data[0].statusCode);
					}
			
				})
			},
			change_margin() {
				var that = this
				if (this.allow_readpw != 'yes') {
					this.$prompt('请输入密码', '提示', {
						confirmButtonText: '确定',
						cancelButtonText: '取消',
						inputType: 'password',
					}).then(({
						value
					}) => {
						if (value == '621890') {
							this.$message({
								type: 'success',
								message: '密码正确:'
							});
							that.allow_readpw = 'yes'
						} else {
							this.$message({
								type: 'error',
								message: '密码出错'
							});
							return
						}
					}).catch(() => {
						this.$message({
							type: 'info',
							message: '取消输入'
						});
						return
					});

				}

				const data = {
					module_name: "yxk_tool.check_server",
					function_name: "check_account_margin",
					args: [this.account_choice],
					kwargs: {
						'margin_change': this.margin_change,
						'margin_set': this.margin_set,
						'moneyindex': '',
						'user': this.$store.state.adminInfo.name
					}
				};


				that.$axios.post(that.lpcallfunction, data).then(response => {
					console.log(response.data, 'check_account_margin');
					if (response.status = 200) {
						if (response.data[0].code == 'error') {
							this.$message({
								message: response.data[0].message,
								type: 'error'
							});

						} else {
							this.$message({
								message: '完成',
								type: 'success'
							});
							that.result = response.data[0].message.trim()
						}
					} else {
						console.log(response.data[0].statusCode);
					}

				})
			},


			get_tradesys_account() {
				var that = this;
				// console.log(that.lpapi2)

				let sql =
					"select * from `LP_account_list` where check_flag ='yes' ORDER BY account_type  ;"
				that.$axios.post(that.lpapi2, "form=get_data&sql=" + sql).then(response => {

					console.log(response, 'LP_account_list')
					let plat_list = []
					if (response.status = 200) {
						that.account_options = []
						that.program_code_options = []
						// that.LP_account_list = response.data;
						for (var i = 0; i < response.data.length; i++) {
							let char = {
								value: response.data[i]['program_code'],
								// label: response.data[i]['account'],
								label: response.data[i]['program_code'],

							};
							let char1 = {
								value: response.data[i]['account'],
								// label: response.data[i]['account'],
								label: response.data[i]['account'],

							};
							that.account_options.push(char1);
							that.program_code_options.push(char);
						}

					} else {
						console.log(response.data.statusCode);
					}
				})


			},
			get_exchange_arrange() {
				var that = this;
				console.log(that.lpapi2)




				let sql =
					"select * ,date_format(datetime,'%Y-%m-%d') as do_datetime from `LP_tradesys_margin`  where program_code='" +
					this.program_code_choice + "' ORDER BY datetime desc ;"
				that.arrange_data = []
				that.$axios.post(that.lpapi2, "form=get_data&sql=" + sql).then(response => {

					console.log(response.data[0], 'LP_tradesys_margin')

					if (response.status = 200) {
						if (response.data[0].hasOwnProperty('message')) {
							that.arrange_data = []
						} else {
							that.arrange_data = response.data;
						}
						// that.arrange_data = response.data;
					} else {
						console.log(response.data.statusCode);
					}
				})


			},





		},
	}
</script>

<style>
	.result-container {
		margin: 5px;
		display: flex;
		align-items: center;
		flex: 1;
		min-height: 0;
	}

	.result-label {
		font-size: medium;
		padding: 10px;
	}

	.result-pre {
		font-size: medium;
		padding: 10px;
		border: 1px solid #ccc;
		min-width: 30%;
		flex: 1;
		overflow-y: auto;
		margin: 0;
	}

	.result-pre span {
		display: block;
	}
	.el-table .bacOrangeRed {
		background: OrangeRed;
	}

	.el-table .bacorange {
		background: orange;
	}

	.el-table .bacpurple {
		background: purple;
	}

	.el-table .success-row {
		background: grey;
		color: white;
	}

	.table_container {
		margin: 20px 5%;
		/* background-color: #0000FF; */
	}

	.el-table .grey {
		background: Silver;
	}

	.el-table .DarkGray {
		background: DarkGray;
	}

	.el-table .LightCoral {
		background: LightCoral;
		color: white;
	}

	.el-table .LimeGreen {
		background: LimeGreen;
	}

	.el-table .green {
		background: green;
	}

	.el-table .LightSlateGray {
		background: LightSlateGray;
	}

	.el-table .red {
		background: red;
		color: white;
	}

	.el-table .orange {
		background: NavajoWhite;
		color: black;
	}

	.el-table .blue {
		background: blue;
	}

	.el-table .purple {
		background: Violet;
		color: black;
	}

	.el-table .LightSteelBlue {
		background: LightSteelBlue;
	}

	.el-table .Goldenrod {
		background: Goldenrod;
	}

	.el-table .xingmu {
		background: Goldenrod;
		color: red;
		font-weight: bold;

	}


	.el-table .black {
		background: black;
		color: white;
	}

	.el-table .green {
		background: green;
		color: white;
	}

	.el-table .CornflowerBlue {
		background: CornflowerBlue;
		color: white;
	}

	.el-table .DodgerBlue {
		background: DodgerBlue;
	}
</style>